<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%guarantee_company}}".
 *
 * @property integer $id
 * @property string $sign_code
 * @property string $name
 * @property string $note
 *
 * @property BankGuaranteeCompanyBind[] $bankGuaranteeCompanyBinds
 * @property Bank[] $banks
 * @property GuaranteeCompanyDotSite[] $guaranteeCompanyDotSites
 */
class GuaranteeCompany extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%guarantee_company}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sign_code', 'name'], 'required'],
            [['note'], 'string'],
            [['sign_code'], 'string', 'max' => 32],
            [['name'], 'string', 'max' => 50],
            [['sign_code'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'sign_code' => 'Sign Code',
            'name' => 'Name',
            'note' => 'Note',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBankGuaranteeCompanyBinds()
    {
        return $this->hasMany(BankGuaranteeCompanyBind::className(), ['guarantee_company_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBanks()
    {
        return $this->hasMany(Bank::className(), ['id' => 'bank_id'])->viaTable('{{%bank_guarantee_company_bind}}', ['guarantee_company_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGuaranteeCompanyDotSites()
    {
        return $this->hasMany(GuaranteeCompanyDotSite::className(), ['guarantee_company_id' => 'id']);
    }
}
